package com.ayou.eggguard.farm.controller;

import com.ayou.common.utils.PageBean;
import com.ayou.common.utils.Result;
import com.ayou.eggguard.farm.pojo.Case;
import com.ayou.eggguard.farm.service.CaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/case")
public class CaseController {

    @Autowired
    private CaseService caseService;

    @GetMapping("/getCases")
    public Result<PageBean<Case>> getCases(int pageNum,
                                           int pageSize,
                                           @RequestParam(required = false) String caseNumber){
        PageBean<Case> pb=caseService.getCases(pageNum,pageSize,caseNumber);
        return Result.success(pb);
    }

    @PostMapping("/add")
    public Result addCase(@RequestBody Case c){
        caseService.add(c);
        return Result.success();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Case c){
        caseService.update(c);
        return Result.success();
    }

    @GetMapping("/delete")
    public Result delete(Integer id){
        caseService.delete(id);
        return Result.success();
    }

    @GetMapping("/getCaseFrequency")
    public Result<List<Map<String,Object>>> getCaseFrequency(){
        List<Map<String,Object>> list=caseService.getCaseFrequency();
        return Result.success(list);
    }

    @GetMapping("/getBlightCount")
    public Result<List<Map<String,Object>>> getBlightCount(){
        List<Map<String,Object>> list=caseService.getBlightCount();
        return Result.success(list);
    }

}
